//
//  ListViewController.m
//  Rainbow
//
//  Created by Alex on 28/07/09.
//  Copyright 2009 Erasmus Software. All rights reserved.
//

#import "ListViewController.h"


@implementation ListViewController

-(id) init
{
	if (![super initWithNibName:@"ListView" bundle:nil])
		return nil;
	[self setTitle:@"List View"];
	tableView = [[NSTableView alloc] init];
	return self;
}

-(NSTableView*) tableView
{
	return tableView;
}

-(void)setUp:(AppController*)AppUp
{
	up = AppUp;
}

-(void)setDvdList:(Dvd*)dvdList
{
	dvd_list = dvdList;
}

- (int) numberOfRowsInTableView:(NSTableView *)tv
{
	return [dvd_list count];
}

- (id) tableView:(NSTableView *)tv objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
{
	NSDictionary *item = [NSDictionary alloc];
	item = [dvd_list itemAtIndex:row];
	
	if (YES == [[tableColumn identifier] isEqualToString:kTitle])
	{
		return [item objectForKey:kTitle];
	}
	else if (YES == [[tableColumn identifier] isEqualToString:kDirector])
	{
		return [item objectForKey:kDirector];
	}
	else if (YES == [[tableColumn identifier] isEqualToString:kYear])
	{
		return [item objectForKey:kYear];
	}
	return nil;
}

- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
{
	NSLog(@"A\n");
	[[NSNotificationCenter defaultCenter] postNotificationName:kSelectionDidChange object:nil];
}

-(void)dealloc
{
	[tableView release];
	[super dealloc];
}

@end
